﻿using System.Drawing;

namespace TowerDefense_MLP
{
    public enum TOWER_TYPE { NONE, CANON, WATER, FIRE };
    
    public abstract class Tower
    {
        #region ATTRIBUTES

        protected int _AtackValue;
        protected int _Range;
        protected int _Firerate;
        protected int _Value;
        protected Point _position;
        protected Bitmap _towerImg;
        protected int _iterator;
        protected string _imageTower;
        protected int _upgradesLeft;

        #region Getters/Setters
        public int AtackValue
        {
            get { return _AtackValue; }
        }
        public int Range
        {
            get { return _Range; }
        }
        public int Firerate
        {
            get { return _Firerate; }
        }
        public int Value
        {
            get { return _Value; }
        }
        public Point Position
        {
            get { return this._position; }
            set { this._position = value; }
        }
        public Bitmap TowerImage
        {
            get { return this._towerImg; }
        }
        public int UpgradesLeft
        {
            get { return _upgradesLeft; }
            set { _upgradesLeft = value; }
        }

        #endregion
        #endregion

        #region METHODS

        public abstract int Atack(out TOWER_TYPE t);

        public Tower(int x, int y)
        {
            this._position = new Point(x, y);
            this._upgradesLeft = 2;
        }

        public void Upgrade()
        {
            this._AtackValue += (int)(this._AtackValue*0.4);
            this._Firerate -= (int)(this._Firerate*0.5);
            this._Range += (int)(this._Range*0.4);
            this._Value += this._Value;
            this._imageTower += "I";
            this._towerImg = new Bitmap(this._imageTower + ".png");
            this._upgradesLeft -= 1;
        }

        public bool ReadyToAtack()
        {
            if (this._iterator == 0)
                return true;
            else
            {
                this._iterator--;
                return false;
            }
        }
        #endregion
    }

    class CanonTower : Tower
    {
        public CanonTower(int x, int y) : base(x, y)
        {
            this._AtackValue = 80;
            this._Firerate = 6;
            this._imageTower = "images\\canonTower";
            this._Range = 175;
            this._Value = 100;
            this._iterator = 0;
            this._towerImg = new Bitmap(@"images\canonTower.png");
        }

        public override int Atack(out TOWER_TYPE hitBy)
        {
            this._iterator = this._Firerate;
            hitBy = TOWER_TYPE.CANON;

            return this._AtackValue;
        }
    }

    class FireTower : Tower
    {
        public FireTower(int x, int y) : base(x, y)
        {
            this._AtackValue = 40;
            this._Firerate = 3;
            this._imageTower = "images\\fireTower";
            this._Range = 130;
            this._Value = 170;
            this._iterator = 0;
            this._towerImg = new Bitmap(@"images\fireTower.png");
        }

        public override int Atack(out TOWER_TYPE hitBy)
        {
            this._iterator = this._Firerate;
            hitBy = TOWER_TYPE.FIRE;

            return this._AtackValue;
        }
    }

    class WaterTower : Tower
    {
        public WaterTower(int x, int y) : base(x, y)
        {
            this._AtackValue = 50;
            this._Firerate = 4;
            this._imageTower = "images\\waterTower";
            this._Range = 150;
            this._Value = 80;
            this._iterator = 0;
            this._towerImg = new Bitmap(@"images\waterTower.png");
        }

        public override int Atack(out TOWER_TYPE hitBy)
        {
            this._iterator = this._Firerate;
            hitBy = TOWER_TYPE.WATER;

            return this._AtackValue;
        }
    }
}
